package com.mobi.Survey.uicomponents;

import android.content.Context;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.mobi.Survey.controller.SurveyDetailPojo;
import com.mobi.Survey.utils.Device;
/**
 * 
 * <p>
 * <b>Author:</b> Yahya Arshad
 * <p>
 * <b>Company:</b> Mobi Media Soft
 * <p>
 * <b> Website:</b> www.mobimediasoft.com
 * <p>
 * CustomEditText.java
 * 
 * 
 */
public class CustomEditText extends EditText
{
	public static final String MULTILINE = "textMultiLine";
	public static final String PHONE = "phone";
	public static final String SINGLE_LINE = "textSingleLine";
	public static final String EMAIL = "textEmailAddress";
	public static final String NUMBER_DECIMAL = "numberDecimal";
	public static final String NUMBER_DECIMAL_SIGNED = "numberSigned";
	private Context ctx;
	LinearLayout ll;

	public CustomEditText(Context context, SurveyDetailPojo sdp,
			boolean editable)
	{
		super(context);
		this.ctx = context;
		ll = new LinearLayout(ctx);

		ll.setOrientation(LinearLayout.VERTICAL);
		this.setWidth(Device.getInstance().getPercentWidth(1f));
		if (sdp.getControlParameter().equalsIgnoreCase(PHONE))
		{
			this.setInputType(InputType.TYPE_CLASS_PHONE
					| InputType.TYPE_CLASS_PHONE);
			this.setSingleLine(true);
		} else if (sdp.getControlParameter().equalsIgnoreCase(SINGLE_LINE))
		{
			// this.setInputType(InputType.TYPE_CLASS_TEXT);
			this.setSingleLine(true);
		} else if (sdp.getControlParameter().equalsIgnoreCase(
				NUMBER_DECIMAL_SIGNED))
		{
			this.setInputType(InputType.TYPE_CLASS_NUMBER
					| InputType.TYPE_NUMBER_FLAG_SIGNED);
			this.setSingleLine(true);
		} else if (sdp.getControlParameter().equalsIgnoreCase(NUMBER_DECIMAL))
		{
			this.setInputType(InputType.TYPE_CLASS_NUMBER
					| InputType.TYPE_NUMBER_FLAG_DECIMAL);
			this.setSingleLine(true);
		} else if (sdp.getControlParameter().equalsIgnoreCase(EMAIL))
		{
			this.setInputType(InputType.TYPE_CLASS_TEXT
					| InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
			this.setSingleLine(true);
		} else if (sdp.getControlParameter().equalsIgnoreCase(MULTILINE))
		{
			this.setHeight(Device.getInstance().getPercentHeight(.2f));

		} else
		{
			// Default Edit Text
			this.setHeight(Device.getInstance().getPercentHeight(.2f));
		}
		if (sdp.getControlParameter() != null
				&& sdp.getControlParameter().length() > 0)
		{

		}

		if (sdp.getControlText() != null && sdp.getControlText().length() > 0)
		{
			CustomTextView ctv = new CustomTextView(ctx);
			ctv.setCustomColor(sdp);
			ctv.setText(sdp.getControlText());
			ll.addView(ctv);
		}
		String valUser = sdp.getUserValue();
		String valDefault = sdp.getDefaultValue();
		
		if (valUser.length() == 0)
		{
			this.setText(valDefault);
		} else
		{
			this.setText(valUser);
		}

		if (!editable)
			this.setEnabled(false);
		ll.addView(this);

	}

	public View getView()
	{
		return ll;
	}

}
